<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-product__product}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.productId" placeholder="productId" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('product:product:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('product:product:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="productId" label="产品ID" header-align="center" align="center"></el-table-column>
        <el-table-column prop="productName" label="产品名称" header-align="center" align="center"></el-table-column>
        <el-table-column prop="title" label="产品标题" header-align="center" align="center"></el-table-column>
        <el-table-column prop="mainPic" label="产品图片" header-align="center" align="center">
          <template slot-scope="scope">
            <el-image  :src="scope.row.mainPic" :preview-src-list="[scope.row.mainPic]"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="freeInd" label="是否免费" header-align="center" align="center">
          <template slot-scope="scope">
          <span>
           {{scope.row.freeInd=='1'?"免费":"付费"}}
           </span>
           </template>
        </el-table-column>
        <el-table-column prop="total" label="金额" header-align="center" align="center"></el-table-column>
        <el-table-column prop="isTop" label="是否置顶" header-align="center" align="center">
          <template slot-scope="scope">
          <span>
           {{scope.row.isTop=='1'?"置顶":"不置顶"}}
           </span>
           </template>
        </el-table-column>
        <el-table-column prop="priority" label="优先级" header-align="center" align="center"></el-table-column>
        <el-table-column prop="gradeId" label="级别" header-align="center" align="center">
          <template slot-scope="scope">
             <span>{{ changeStatusValue(scope.row.gradeId)}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="quantityNumber" label="剩余数量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="browsesNumber" label="浏览数量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="totalNumber" label="产品总数量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('product:product:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.productId)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('product:product:delete')" type="text" size="small" @click="deleteHandle(scope.row.productId)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './product-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/product/product/page',
        getDataListIsPage: true,
        exportURL: '/product/product/export',
        deleteURL: '/product/product',
        deleteIsBatch: true
      },
      dataForm: {
        productId: ''
      },
      gradeList:[]
    }
  },
  created() {
   this.getGradeList () 
  },
  components: {
    AddOrUpdate
  },methods: {
    getGradeList () {
      this.$http.get('/member/grade/list').then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }

        this.gradeList = res.data
    
      }).catch(() => {})
    },
    changeStatusValue(gradeId) {
      let dataList=this.gradeList
       for (var i = 0; i < dataList.length; i++) {
        if (dataList[i].gradeId === gradeId) {
           return dataList[i].gradeName;
         }
       }
  }
}
}
</script>
